/**
 * Created by HSH on 2016/3/6.
 */
define(function (require) {
    'use strict';
    var loginApp = require('app/loginApp');
    return {
        service: function ($scope, AUTH_EVENTS) {
            $scope.dialogText = $.i18n.text('login_title');
            $scope.cancelText = $.i18n.text('cancel_title');
            $scope.uNameText = $.i18n.text('user_title');
            $scope.pwdText = $.i18n.text('pwd_title');
            $scope.uNamePlaceholder = $.i18n.text('uNamePlaceholder');
            $scope.pwdPlaceholder = $.i18n.text('pwdPlaceholder');
            $scope.forgetLinText = $.i18n.text('forgetPWdLink');
            $scope.autoLoginText = $.i18n.text('autoLoginTitle');
            $scope.UserAuthenticationInfo = {
                userName: '',
                passWord: '',
                isAutoLogin: true
            };

            $scope.isErrorMessageShow = false;
            var FullMonitor = function () {
            };
            FullMonitor.prototype = {
                userName: function (newVal, oldVal, scope) {
                    if (newVal === oldVal) {
                    }
                    else {
                        scope.UserAuthenticationInfo.passWord = '';
                        scope.isErrorMessageShow = false;
                    }
                }
            };
            var fullMonitor = new FullMonitor();
            $scope.JumpThirdPage = function () {

            };
            $scope.$watch('UserAuthenticationInfo.userName', fullMonitor.userName);
            $scope.loginSubmit = function (UserAuthenticationInfo) {
                if (UserAuthenticationInfo.userName === '') {
                    $scope.isErrorMessageShow = true;
                    $scope.errorMessage = $.i18n.text('user_no_empty');
                    return false;
                } else if (UserAuthenticationInfo.passWord === '') {
                    $scope.isErrorMessageShow = true;
                    $scope.errorMessage = $.i18n.text('pwd_no_empty');
                    return false;
                }
                loginApp.UserLoginOperation(UserAuthenticationInfo).done(function (resp) {
                    ePart.log(resp);
                    ePart.pcUtils.closeDialog();
                }).fail(function () {
                    ePart.log('fail');
                });
            };
        }
    }
});
